﻿using System;
using YmtAuth.Domain.EventHistory;
using YmtAuth.Domain.Model.YmatouUserBills.TencentLoginProtection;

namespace YmtAuth.Domain.Repository
{
    /// <summary>
    /// 登录日志
    /// </summary>
    public interface IYmtUserLoginHistoryRepository : IRepository_v1<YmtUserLoginEvent, string>
    {        
        void LogAsync(YmtUserLoginEvent @event);   
        void UpdateLoginTimeAsync(int userId);
        void SaveTencentLoginProtectionResult(TencentLoginProtectionEvent @event);
        /// <summary>
        /// 获取用户登录计数器。异常返回：-1
        /// </summary>
        /// <param name="countName">业务大类</param>
        /// <param name="key">业务小类</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">接收时间</param>
        /// <returns>返回计数器总数</returns>
        int GetUserLoginCount(string countName,string key,DateTime startTime,DateTime endTime);
        /// <summary>
        /// 从计数器服务获取统计登录IP次数
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="minutes"></param>
        /// <returns></returns>
        int GetLoginIpCount(string countName, string ip, DateTime startTime, DateTime endTime);
        /// <summary>
        /// 地址登录IP次数
        /// </summary>
        /// <param name="countName"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        int IncrementLoginIpCount(string countName, string ip,bool success);

        /// <summary>
        /// 查询在 {countStartTime} 分钟内 设备/ClientId 登录 成功/失败（success）的次数
        /// </summary>
        /// <param name="deviceType"></param>
        /// <param name="deviceId"></param>
        /// <param name="success"></param>
        /// <param name="countStartTime"></param>
        /// <returns></returns>
        int GetLoginDeviceCount(byte deviceType, string deviceId, bool success, int countStartTime);
    }
}
